package cn.idongjia.mqserver.impl;

import cn.idongjia.mq.producer.IProducer;
import cn.idongjia.mqserver.pojo.Message;
import cn.idongjia.mqserver.services.SendMessageService;
import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * Created by renxianlong on 16/3/29.
 */
@Path("/message")
@Produces({ContentType.APPLICATION_JSON_UTF_8})
@Component("sendMessageService")
public class SendMessageImpl implements SendMessageService{

    @Resource
    public IProducer producer;

    @PUT
    @Path("send")
    @Consumes({MediaType.APPLICATION_JSON})
    @Override
    public void sendMessage(Message message) {
        producer.send(message.getTopic(),message.getKey(),message.getMessage());
    }
}
